//
//  CategoryView.m
//  Comma
//
//  Created by dlios on 15-1-13.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "CategoryView.h"
#import "Masonry.h"
#import "GlobalMacro.h"
#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
@implementation CategoryView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createButton];
        self.choiceButtonTag = -1;
        [self setBackgroundColor:[UIColor whiteColor]];
        [self setClipsToBounds:YES];
        
    }
    return self;
}

- (void)createButton
{
    self.width = 78;
    self.height = 96;
    self.buttonHeight = 108;
    self.interval = 226;
    if (iPhone6) {
        
    } else if (iPhone6Plus) {
//        self.width = 78 * 1.656;
//        self.height = 96 * 1.656;
    } else {
        self.width = 78 * 0.85;
        self.height = 96 * 0.85;
        self.buttonHeight = 108 * 0.85;
        self.interval = 226 * 0.85;
    }

    NSArray *normalArray = [NSArray arrayWithObjects:@"Button_notice",@"Button_Activities", @"Button_Lecture", @"Button_Date", @"Button_Match", @"Button_Market", @"Button_Greedy", @"Button_Students", @"Button_lover", @"Button_Retrieve", @"Button_Help", @"Button_Nonsense", nil];
    NSArray *highLightArray = [NSArray arrayWithObjects:@"Button_notice_effect",@"Button_Activities_effect", @"Button_Lecture_effect", @"Button_Date_effect", @"Button_Match_effect", @"Button_Market_effect", @"Button_Greedy_effect", @"Button_Students_effect", @"Button_lover_effect", @"Button_Retrieve_effect", @"Button_Help_effect", @"Button_Nonsense_effect", nil];
    NSArray *catArr = [NSArray arrayWithObjects:@"tongzhi",@"huodong",@"jiangzuo", @"yueme",@"bisai",@"shichang",@"chihuo", @"shetuan",@"tuodan",@"xunwu",@"qiuzu", @"chedan",nil];
    
    for (int i = 0; i < 12; i++) {
        // 创建类别button
        UIButton *categoryButton = [[UIButton alloc] initWithFrame:CGRectMake(31.5 + i % 3 * _width + (SCREEN_WIDTH - 31.5 * 2 - _width * 3) / 2 * (i % 3), 14 + i / 3 * _height + i / 3 * (SCREEN_HEIGHT - _interval - _height * 4) / 3, _width, _height)];
        
        [categoryButton setTitle:[catArr objectAtIndex:i] forState:UIControlStateNormal];
        [categoryButton.titleLabel setFont:[UIFont systemFontOfSize:0]];
        [categoryButton setTag:10 + i];
        [categoryButton setBackgroundImage:[UIImage imageNamed:[normalArray objectAtIndex:i]] forState:UIControlStateNormal];
        [categoryButton setBackgroundImage:[UIImage imageNamed:[highLightArray objectAtIndex:i]] forState:UIControlStateSelected];
        [self addSubview:categoryButton];
    }
    // 创建'全部'button
    UIButton *allButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - _width / 2, SCREEN_HEIGHT - 59 - 64 - 64, _width, _buttonHeight)];
    [allButton setTag:22];
    [allButton setBackgroundImage:[UIImage imageNamed:@"Button_All"] forState:UIControlStateNormal];
    [allButton setBackgroundImage:[UIImage imageNamed:@"Button_All_effect"] forState:UIControlStateSelected];
    [self addSubview:allButton];
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
